﻿using System;
using System.Data;
using System.Collections;
using CE.Database;

/// <summary>
/// Summary description for LMGCarMoreDetailDB
/// </summary>
/// 
namespace CE.CarInsurance
{
    public class LMGCarMoreDetailDB
    {
        public LMGCarMoreDetailDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(LMGCarMoreDetail lmgcarmoredetail)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCarMoreDetailInsertUpdateSingleItemLMG";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarMoreDetailId", lmgcarmoredetail.CECarMoreDetailId);
            _sPara.Add("@CECarId", lmgcarmoredetail.CECarId);
            _sPara.Add("@ProviderCompanyId", lmgcarmoredetail.ProviderCompanyId);
            _sPara.Add("@AnnualPremium", lmgcarmoredetail.AnnualPremium);
            _sPara.Add("@TermPremium", lmgcarmoredetail.TermPremium);
            _sPara.Add("@Name", lmgcarmoredetail.Name);
            _sPara.Add("@IdentificationNo", lmgcarmoredetail.IdentificationNo);
            _sPara.Add("@Occupation", lmgcarmoredetail.Occupation);
            _sPara.Add("@ContactNo", lmgcarmoredetail.ContactNo);
            _sPara.Add("@OfficePhoneNo", lmgcarmoredetail.OfficePhoneNo);
            //_sPara.Add("@LicenseNo", lmgcarmoredetail.LicenseNo);
            _sPara.Add("@BeneficiaryName", lmgcarmoredetail.BeneficiaryName);

            _sPara.Add("@CarPlate", lmgcarmoredetail.CarPlate);
            _sPara.Add("@CarPlateProvince", lmgcarmoredetail.CarPlateProvince);
            _sPara.Add("@PresentAddress", lmgcarmoredetail.PresentAddress);
            _sPara.Add("@SubDistrict", lmgcarmoredetail.SubDistrict);
            _sPara.Add("@District", lmgcarmoredetail.District);
            _sPara.Add("@Province", lmgcarmoredetail.Province);
            _sPara.Add("@PostalCode", lmgcarmoredetail.PostalCode);
            _sPara.Add("@IsMailingAddressDiff", lmgcarmoredetail.IsMailingAddressDiff);
            _sPara.Add("@MailingAddress", lmgcarmoredetail.MailingAddress);
            _sPara.Add("@MailingSubDistrict", lmgcarmoredetail.MailingSubDistrict);
            _sPara.Add("@MailingDistrict", lmgcarmoredetail.MailingDistrict);
            _sPara.Add("@MailingProvince", lmgcarmoredetail.MailingProvince);
            _sPara.Add("@MailingPostalCode", lmgcarmoredetail.MailingPostalCode);
            _sPara.Add("@EngineNumber", lmgcarmoredetail.EngineNumber); //Sakthi on 24 Jun 2011
            _sPara.Add("@ChassisNumber", lmgcarmoredetail.ChassisNumber); //Sakthi on 24 Jun 2011
            //_sPara.Add("@IsRegisteredOwner", lmgcarmoredetail.IsRegisteredOwner); //Sakthi on 24 Jun 2011
            _sPara.Add("@IsCTPL", lmgcarmoredetail.IsCTPL);
            _sPara.Add("@CTPL", lmgcarmoredetail.CTPL);

            /*_sPara.Add("@No", lmgcarmoredetail.No);
            _sPara.Add("@Soi", lmgcarmoredetail.Soi);
            _sPara.Add("@Subzone", lmgcarmoredetail.Subzone);
            _sPara.Add("@Province", lmgcarmoredetail.Province);
            _sPara.Add("@Building", lmgcarmoredetail.Building);
            _sPara.Add("@Street", lmgcarmoredetail.Street);
            _sPara.Add("@District", lmgcarmoredetail.District);
            _sPara.Add("@PostalCode", lmgcarmoredetail.PostalCode);
            _sPara.Add("@IsDifferentAddress", lmgcarmoredetail.IsDifferentAddress);
            _sPara.Add("@NoMailing", lmgcarmoredetail.NoMailing);
            _sPara.Add("@SoiMailing", lmgcarmoredetail.SoiMailing);
            _sPara.Add("@SubzoneMailing", lmgcarmoredetail.SubzoneMailing);
            _sPara.Add("@ProvinceMailing", lmgcarmoredetail.ProvinceMailing);
            _sPara.Add("@BuildingMailing", lmgcarmoredetail.BuildingMailing);
            _sPara.Add("@StreetMailing", lmgcarmoredetail.StreetMailing);
            _sPara.Add("@DistrictMailing", lmgcarmoredetail.DistrictMailing);
            _sPara.Add("@PostalCodeMailing", lmgcarmoredetail.PostalCodeMailing);
            _sPara.Add("@VehicleNo", lmgcarmoredetail.VehicleNo);
            _sPara.Add("@EngineNo", lmgcarmoredetail.EngineNo);
            _sPara.Add("@ChassisNo", lmgcarmoredetail.ChassisNo);
            _sPara.Add("@VehicleColor", lmgcarmoredetail.VehicleColor);
            _sPara.Add("@VehicleProvince", lmgcarmoredetail.VehicleProvince);
            _sPara.Add("@PolicyStartDate", lmgcarmoredetail.PolicyStartDate); */
            _sPara.Add("@PaymentOption", lmgcarmoredetail.PaymentOption);
            _sPara.Add("@PaymentType", lmgcarmoredetail.PaymentType);
            _sPara.Add("@PaymentBank", lmgcarmoredetail.PaymentBank); //Sakthi on 24 Jun 2011

            _sPara.Add("@OrderRefNoId", lmgcarmoredetail.OrderRefNoId);
            _sPara.Add("@OrderRefNo", lmgcarmoredetail.OrderRefNo);
            _sPara.Add("@PaymentStatus", lmgcarmoredetail.PaymentStatus);

            _sPara.Add("@QuoteRefNo", lmgcarmoredetail.QuoteRefNo);
            _sPara.Add("@RefCEUserId", lmgcarmoredetail.RefCEUserId);
            _sPara.Add("@ViewedDetailId", lmgcarmoredetail.ViewedDetailId);
            _sPara.Add("@CarResultId", lmgcarmoredetail.CarResultId);
            _sPara.Add("@Ninfo4", lmgcarmoredetail.Ninfo4); // For AgentId
            _sPara.Add("@Ninfo5", lmgcarmoredetail.Ninfo5); // Submission
            _sPara.Add("@Status", lmgcarmoredetail.Status);
            _sPara.Add("@Info1", lmgcarmoredetail.Info1);
            _sPara.Add("@Info2", lmgcarmoredetail.Info2);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public LMGCarMoreDetail GetCarMoreDetail(Int64 CarId, Int64 CEUserId)
        {
            LMGCarMoreDetail _lmgcarmoredetail = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarMoreDetailSelectSingleItemLMG";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarID", CarId);
            _spara.Add("@RefCEUserId", CEUserId);

            DataTable _dt = _db.GetDataTableBySP(_spName, _spara);
            if (_dt != null)
            {
                if (_dt.Rows.Count > 0)
                {
                    _lmgcarmoredetail = new LMGCarMoreDetail();
                    _lmgcarmoredetail = FillDataRecord(_dt);
                }
            }
            return _lmgcarmoredetail;
        }

        private LMGCarMoreDetail FillDataRecord(DataTable myDataTable)
        {
            LMGCarMoreDetail myCarMoreDetail = new LMGCarMoreDetail();
            myCarMoreDetail.CECarMoreDetailId = Convert.ToInt64(myDataTable.Rows[0]["CECarMoreDetailId"].ToString());
            myCarMoreDetail.CECarId = Convert.ToInt64(myDataTable.Rows[0]["CECarId"].ToString());
            myCarMoreDetail.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[0]["ProviderCompanyId"].ToString());
            myCarMoreDetail.AnnualPremium = Convert.ToSingle(myDataTable.Rows[0]["AnnualPremium"].ToString());
            myCarMoreDetail.TermPremium = Convert.ToSingle(myDataTable.Rows[0]["TermPremium"].ToString());
            myCarMoreDetail.Name = myDataTable.Rows[0]["Name"].ToString();
            if (myDataTable.Rows[0]["IdentificationNo"] != null)
            {
                myCarMoreDetail.IdentificationNo = myDataTable.Rows[0]["IdentificationNo"].ToString();
            }
            myCarMoreDetail.Occupation = myDataTable.Rows[0]["Occupation"].ToString();
            myCarMoreDetail.ContactNo = myDataTable.Rows[0]["ContactNo"].ToString();
            myCarMoreDetail.OfficePhoneNo = myDataTable.Rows[0]["OfficePhoneNo"].ToString();
            //myCarMoreDetail.LicenseNo = myDataTable.Rows[0]["LicenseNo"].ToString();
            myCarMoreDetail.BeneficiaryName = myDataTable.Rows[0]["BeneficiaryName"].ToString();

            myCarMoreDetail.CarPlate = myDataTable.Rows[0]["CarPlate"].ToString();
            myCarMoreDetail.CarPlateProvince = myDataTable.Rows[0]["CarPlateProvince"].ToString();
            myCarMoreDetail.PresentAddress = myDataTable.Rows[0]["PresentAddress"].ToString();
            myCarMoreDetail.SubDistrict = myDataTable.Rows[0]["SubDistrict"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsMailingAddressDiff = Convert.ToBoolean(myDataTable.Rows[0]["IsMailingAddressDiff"].ToString());
            myCarMoreDetail.MailingAddress = myDataTable.Rows[0]["MailingAddress"].ToString();
            myCarMoreDetail.MailingSubDistrict = myDataTable.Rows[0]["MailingSubDistrict"].ToString();
            myCarMoreDetail.MailingDistrict = myDataTable.Rows[0]["MailingDistrict"].ToString();
            myCarMoreDetail.MailingProvince = myDataTable.Rows[0]["MailingProvince"].ToString();
            myCarMoreDetail.MailingPostalCode = myDataTable.Rows[0]["MailingPostalCode"].ToString();
            myCarMoreDetail.EngineNumber = myDataTable.Rows[0]["EngineNumber"].ToString(); //Sakthi on 24 Jun 2011
            myCarMoreDetail.ChassisNumber = myDataTable.Rows[0]["ChassisNumber"].ToString(); //Sakthi on 24 Jun 2011
            //myCarMoreDetail.IsRegisteredOwner = Convert.ToBoolean(myDataTable.Rows[0]["IsRegisteredOwner"].ToString());//Sakthi on 24 Jun 2011
            myCarMoreDetail.IsCTPL = Convert.ToBoolean(myDataTable.Rows[0]["IsCTPL"].ToString());
            myCarMoreDetail.CTPL = Convert.ToSingle(myDataTable.Rows[0]["CTPL"].ToString());

            /*myCarMoreDetail.No = myDataTable.Rows[0]["No"].ToString();
            myCarMoreDetail.Soi = myDataTable.Rows[0]["Soi"].ToString();
            myCarMoreDetail.Subzone = myDataTable.Rows[0]["Subzone"].ToString();
            myCarMoreDetail.Province = myDataTable.Rows[0]["Province"].ToString();
            myCarMoreDetail.Building = myDataTable.Rows[0]["Building"].ToString();
            myCarMoreDetail.Street = myDataTable.Rows[0]["Street"].ToString();
            myCarMoreDetail.District = myDataTable.Rows[0]["District"].ToString();
            myCarMoreDetail.PostalCode = myDataTable.Rows[0]["PostalCode"].ToString();
            myCarMoreDetail.IsDifferentAddress = Convert.ToBoolean(myDataTable.Rows[0]["IsDifferentAddress"].ToString());
            myCarMoreDetail.NoMailing = myDataTable.Rows[0]["NoMailing"].ToString();
            myCarMoreDetail.SoiMailing = myDataTable.Rows[0]["SoiMailing"].ToString();
            myCarMoreDetail.SubzoneMailing = myDataTable.Rows[0]["SubzoneMailing"].ToString();
            myCarMoreDetail.ProvinceMailing = myDataTable.Rows[0]["ProvinceMailing"].ToString();
            myCarMoreDetail.BuildingMailing = myDataTable.Rows[0]["BuildingMailing"].ToString();
            myCarMoreDetail.StreetMailing = myDataTable.Rows[0]["StreetMailing"].ToString();
            myCarMoreDetail.DistrictMailing = myDataTable.Rows[0]["DistrictMailing"].ToString();
            myCarMoreDetail.PostalCodeMailing = myDataTable.Rows[0]["PostalCodeMailing"].ToString();
            myCarMoreDetail.VehicleNo = myDataTable.Rows[0]["VehicleNo"].ToString();
            myCarMoreDetail.EngineNo = myDataTable.Rows[0]["EngineNo"].ToString();
            myCarMoreDetail.ChassisNo = myDataTable.Rows[0]["ChassisNo"].ToString();
            myCarMoreDetail.VehicleColor = myDataTable.Rows[0]["VehicleColor"].ToString();
            myCarMoreDetail.VehicleProvince = myDataTable.Rows[0]["VehicleProvince"].ToString();
            myCarMoreDetail.PolicyStartDate = Convert.ToDateTime(myDataTable.Rows[0]["PolicyStartDate"].ToString());*/

            myCarMoreDetail.PaymentOption = myDataTable.Rows[0]["PaymentOption"].ToString();
            myCarMoreDetail.PaymentType = myDataTable.Rows[0]["PaymentType"].ToString();
            myCarMoreDetail.PaymentBank = myDataTable.Rows[0]["PaymentBank"].ToString();//Sakthi on 24 Jun 2011
            myCarMoreDetail.QuoteRefNo = myDataTable.Rows[0]["QuoteRefNo"].ToString();
            myCarMoreDetail.RefCEUserId = Convert.ToInt64(myDataTable.Rows[0]["RefCEUserId"].ToString());
            myCarMoreDetail.CarResultId = Convert.ToInt64(myDataTable.Rows[0]["CarResultId"].ToString());
            if (myDataTable.Rows[0]["Ninfo4"] != null)
            {
                myCarMoreDetail.Ninfo4 = Convert.ToInt64(myDataTable.Rows[0]["Ninfo4"].ToString());
            }
            if (myDataTable.Rows[0]["Ninfo5"] != null)
            {
                myCarMoreDetail.Ninfo5 = Convert.ToInt32(myDataTable.Rows[0]["Ninfo5"].ToString());
            }
            myCarMoreDetail.Status = Convert.ToBoolean(myDataTable.Rows[0]["Status"].ToString());


            return myCarMoreDetail;
        }

        public DataSet GetCarPolicyDetails(Int64 CarId, Int64 CEId, Int64 CXCoverTypeId, Int64 ProviderCompanyId)
        {
            DataSet _result = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocCarInsuranceTHSelectedPlanSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@CECarId", CarId);
            _spara.Add("@RefCEUserId", CEId);
            _spara.Add("@CITempResultId", CXCoverTypeId);
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);


            using (DataSet _ds = _db.GetDataSet(_spName, _spara))
            {
                if (_ds != null && _ds.Tables.Count > 0 && _ds.Tables[0].Rows.Count > 0)
                {
                    _result = _ds;
                }
            }
            return _result;
        }

        public Int64 CheckConfirmStatus(Int64 CarId, string ResultType)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "sprocCheckUserConfirmStatus";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@CECarId", CarId);
            _sPara.Add("@ResultType", ResultType);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

    }
}